Thread: A question about the place of "printf" with "while" and "{}"

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    3

    A question about the place of "printf" with "while" and "{}"

    Hi,
    I am a beginner of C who is currently using The C Programming Language to self-study.
    However I am confused by one little problem:
    When I put
    Code:
    printf
    inside the
    Code:
    while{}
    , it gives the output of every single loop,
    A question about the place of "printf" with "while" and "{}"-screen-shot-2016-02-20-1-30-17-pm-png
    However, since I want only the final answer and thus try to put the printf out of {}, which is after while, nothing shows then.
    A question about the place of "printf" with "while" and "{}"-screen-shot-2016-02-20-1-29-40-pm-png
    This one with nothing shown is copied directly from the book so I really wonder what's wrong, and how exactly should I modify it to make it output the total number of lines?


    Thank you!

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    You should post your code (using code tags) and output here directly, rather than posting screen shots.

    In the second example, you need to trigger EOF to end the loop. This is done by entering Ctrl-Z (on Windows) or Ctrl-D (on Unix).

  3. #3
    Registered User
    Join Date
    Feb 2016
    Posts
    3
    Thank you, Ctrl-D works.
    And sorry, I see Next time I will post the code directly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-08-2014, 08:12 PM
  2. Replies: 2
    Last Post: 08-19-2012, 06:15 AM
  3. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  4. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM

Tags for this Thread